package jdbc;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

/**
 * 修改某个用户的密码
 * 例如:
 * 将"王克晶"的密码改成"666666"
 *
 * 对应的预编译SQL为:
 * UPDATE userinfo
 * SET password=?
 * WHERE username=?
 */
public class Test4 {
    public static void main(String[] args) {
        try (
             Connection conn = DBUtil.getConnection();
        ){
            String sql = "UPDATE userinfo " +
                         "SET password=? " +
                         "WHERE username=? ";
            PreparedStatement ps = conn.prepareStatement(sql);
            ps.setString(1,"666666");
            ps.setString(2,"王克晶");
            int count = ps.executeUpdate();
            if(count>0){
                System.out.println("修改成功");
            }else{
                System.out.println("修改失败");
            }


        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
